package com.yuan.service;

import com.yuan.dao.AccountDao;
import com.yuan.utlis.DruidUtil;

import java.sql.Connection;
import java.sql.SQLException;

public class AccountService {
    private AccountDao accountDao=new AccountDao();
    public void transfer(String fromName,String toName,double money) throws SQLException {
        Connection conn=null;
        try {
            conn=DruidUtil.getDataSource().getConnection();
            conn.setAutoCommit(false);
            //开始扣款
            accountDao.UpdateAccount(conn,fromName,-money);
            //出现异常
            int i=10/0;
            accountDao.UpdateAccount(conn,toName,money);
            conn.commit();
        } catch (Exception e) {
            e.printStackTrace();
            conn.rollback();
        }
    }
}
